package com.leonzx.base.service.system;

import com.leonzx.base.config.security.Digests;
import com.leonzx.base.constants.IMConstants;
import com.leonzx.base.dao.system.FileOnlineDAO;
import com.leonzx.base.dao.system.InformationDAO;
import com.leonzx.base.entity.system.FileOnline;
import com.leonzx.base.entity.system.Information;
import com.leonzx.base.service.BaseService;
import com.leonzx.base.utils.Constants;
import com.leonzx.base.utils.SQLUtils;
import com.leonzx.base.utils.UUIDUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

/**
 * @Author:李晓雷
 * @Description:
 * @Date: 18/07/11 14:24
 */
@Service
public class InformationService extends BaseService {
    @Autowired
    private InformationDAO informationDAO;

    public List<Information> getAllBaseInformation(Information information) {
        Example example = new Example(FileOnline.class);
        Example.Criteria criteria = example.createCriteria();

        if (StringUtils.isNotBlank(information.getPhoneNumber())) {
            criteria.andLike("phoneNumber", SQLUtils.like(information.getPhoneNumber()));
        }

        if (information.getState() != null) {
            criteria.andEqualTo("state", information.getState());
        }
        return informationDAO.selectByExample(example);
    }
    /**
     * 根据id更新已有信息
     *
     * @param information
     */
    public void update(Information information) {
        informationDAO.updateByPrimaryKeySelective(information);
    }

    public void insert(Information information) {
        information.setId(UUIDUtils.getUUID());
        information.setCreateTime(new Date());
        information.setState(Constants.STATE_VAILD);
        informationDAO.insert(information);
    }

    public Information findById(Information information) {
        return informationDAO.selectByPrimaryKey(information);
    }
}
